package drone.basis.express ;

import com.googlecode.aviator.runtime.function.AbstractFunction ;
import com.googlecode.aviator.runtime.function.FunctionUtils ;
import com.googlecode.aviator.runtime.type.AviatorDouble ;
import com.googlecode.aviator.runtime.type.AviatorObject ;

import java.nio.ByteBuffer ;
import java.nio.ByteOrder ;
import java.util.Map ;

public class FuncF32 extends AbstractFunction
{

	@Override
	public AviatorObject call (
			Map < String , Object > env ,
			AviatorObject arg1 ,
			AviatorObject arg2 ,
			AviatorObject arg3 ,
			AviatorObject arg4
	)
	{
		byte float_hh = FunctionUtils.getNumberValue ( arg1 , env ).byteValue ( ) ;
		byte float_hl = FunctionUtils.getNumberValue ( arg2 , env ).byteValue ( ) ;
		byte float_lh = FunctionUtils.getNumberValue ( arg3 , env ).byteValue ( ) ;
		byte float_ll = FunctionUtils.getNumberValue ( arg4 , env ).byteValue ( ) ;
		ByteBuffer bb = ByteBuffer.allocate ( 4 ).order ( ByteOrder.BIG_ENDIAN ) ;
		bb.put ( float_hh ).put ( float_hl ).put ( float_lh ).put ( float_ll ) ;
		return new AviatorDouble ( ( double ) ( bb.getFloat ( 0 ) ) ) ;
	}

	public String getName ( )
	{
		return "float" ;
	}
}
